class Solution(object):
    def nextGreaterElements(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        s = len(nums)
        nums = nums + nums
        a = [-1] * len(nums)
        stack = []
        for i in range(len(nums)):
            while stack and nums[i] > nums[stack[-1]]:
                res = stack.pop()
                a[res] = nums[i]
            stack.append(i)
        return a[:s]





a = [1,2,1]
s =Solution()
m = s.nextGreaterElements(a)
print(m)

